home *** CD-ROM | disk | FTP | other *** search
/ Enter 2002 August / EnterCD 8_2002.iso / Internet / Adobe GoLive 6.0 / data1.cab / PF_AppDir_Mod_PageGenerator / PageGenerator.java < prev    next >
Encoding:
Java Source  |  2002-03-28  |  5.0 KB  |  144 lines

  1. // ------------------------------------------------------------------
  2. //                                                                        
  3. // Purpose.............:    PageGenerator
  4. // Created.............:    May 8, 2001
  5. // Copyright...........:    (c) 2001 by Adobe Systems
  6. //
  7. // ------------------------------------------------------------------
  8.  
  9. import    java.io.*;
  10. import    java.util.ResourceBundle;
  11. import    java.util.Locale;
  12.  
  13. /**
  14.  * PageGenerator command line main class.
  15.  * For example:
  16.  * <pre>
  17.  * Usage:
  18.  *   PageGenerator urlListFile [savePath [skipFolder [proxyHost [proxyPort]]]]
  19.  * Downloads web pages specified in urlListFile to the folder named by
  20.  * savePath.  Uses proxyHost and proxyPort, if specified, as the proxy server
  21.  * for accessing web sites outside your firewall.
  22.  * savePath is the folder in which PageGenerator saves output files:
  23.  * if not specified, it uses PageGenerator's own folder.
  24.  * If skipFolder is specified and numeric, PageGenerator shortens the URL by
  25.  * that many levels (see EXAMPLES).
  26.  * With extension ".txt", urlListFile contains space-delimited pairs of
  27.  * URLs and filenames:
  28.  *   http://localhost/magazine/project.asp?RECORD_INDEX=3 project.index3.html
  29.  * With any other extension, urlListFile contains an HTML table, with the URL
  30.  * in the leftmost column, the filename in the rightmost column, and URL
  31.  * arguments specified in the intermediate columns (if any) -- in this case
  32.  * the table's first row contains the URL arguments names.
  33.  *   <table>  <!-- 2-column version -->
  34.  *   <tr><td>http://localhost/magazine/project.asp?RECORD_INDEX[Features]=3</td>
  35.  *       <td>project.index3.html</td></tr>
  36.  *   </table>
  37.  * or
  38.  *   <table>  <!-- argument-columns version -->
  39.  *   <tr><td>(ignored)</td>
  40.  *       <td>RECORD_INDEX[Features]</td>  <!-- argument name -->
  41.  *       <td>(ignored)</td></tr>
  42.  *   <tr><td>http://localhost/magazine/project.asp
  43.  *       </td><td>3</td>                  <!-- argument value -->
  44.  *       <td>project.index3.html</td></tr>
  45.  *   </table>
  46.  * EXAMPLES
  47.  *   java PageGenerator c:\\temp\\urls.txt c:\\temp\\saved-site
  48.  * Reads URLs, saves output files in c:\\temp\\saved\\saved-site (creates
  49.  * folder if necessary).
  50.  *   java PageGenerator http://myhost/my-list-page.asp c:\\temp\\saved-site
  51.  * Reads a URLs from HTML dynamically generated by my-list-page.asp.
  52.  *   java PageGenerator /tmp/urls.txt /tmp/saved-site
  53.  * UNIX (MacOS X) usage.  If filenames contain spaces or other special
  54.  * characters, quote them: "/tmp/My Folder/urls.txt"
  55.  *   java PageGenerator /tmp/urls.txt /tmp/saved-site 1
  56.  * As above, but saves URLs like http://myhost/a/b/c.html as
  57.  * /tmp/saved-site/b/c.html, not /tmp/saved-site/a/b/c.html
  58.  *   java PageGenerator /tmp/urls.txt /tmp/saved-site 0 myproxy 8080
  59.  * Uses the proxy server http://myproxy:8080 to access URLs.
  60.  * </pre>
  61.  *
  62.  * @author  Adobe Systems, Inc.
  63.  * @since 1.0
  64.  */
  65. public class PageGenerator {
  66.  
  67.     /**
  68.      * Command line main method
  69.      * @param    argv Command line parameter
  70.      * @return    void
  71.      */
  72.     public static void main(String[] argv) {
  73.         if (argv.length < 1) {
  74.             printUsage();
  75.         }
  76.         String fileName = argv[0];
  77.         String savePath = "";
  78.         int skipFolder  = 0;
  79.         String proxyHost = "";
  80.         String proxyPort = "";
  81.  
  82.         if (argv.length >= 2)    savePath = argv[1];
  83.         try {
  84.             if (argv.length >= 3)    skipFolder = Integer.parseInt(argv[2]);
  85.         } catch(NumberFormatException e ) {
  86.             ResourceBundle rb = ResourceBundle.getBundle("PageGenerator");
  87.             System.err.println(rb.getString("error") + rb.getString("specifyNumber4skipFolder"));
  88.             printUsage();
  89.         }
  90.         if (argv.length >= 4)    proxyHost = argv[3];
  91.         if (argv.length >= 5)    proxyPort = argv[4];
  92.  
  93.         if (savePath.length() > 0) {
  94.             if ((savePath.charAt(0) == '"') && (savePath.charAt(savePath.length()-1) == '"') && (savePath.length() > 3)) {
  95.                 savePath += savePath.substring(1,savePath.length()-2);    //    ex) "f:\a a" => f:\a a
  96.             }
  97.             if (savePath.charAt(savePath.length()-1) != File.separatorChar) {
  98.                 savePath += File.separatorChar;    //    ex) f: => f:\
  99.             }
  100.         }
  101.  
  102.         if (proxyHost.length() > 0) {    // proxy setting
  103.             System.getProperties().put( "proxySet", "true" );
  104.             System.getProperties().put( "proxyHost", proxyHost );
  105.             if (proxyPort.length() > 0) {
  106.                 System.getProperties().put( "proxyPort", proxyPort );
  107.             }
  108.         }
  109.  
  110.         int downloadedCount = 0;
  111.         try {
  112.             UrlList urlList = new UrlList();
  113.             urlList.readFile(fileName, skipFolder);
  114.  
  115.             UrlReplaceDownload urlReplaceDownload = new UrlReplaceDownload(savePath);
  116.             downloadedCount = urlReplaceDownload.replaceDownload(urlList);
  117.             ResourceBundle rb = ResourceBundle.getBundle("PageGenerator");
  118.             print(downloadedCount + rb.getString("filesDownloaded"));
  119.         } catch(Exception e) {
  120.             e.printStackTrace();
  121.         }
  122.         System.exit(downloadedCount);
  123.     }
  124.  
  125.     /**
  126.      * @param    void
  127.      * @return    void
  128.      */
  129.     static void printUsage() {
  130.         ResourceBundle rb = ResourceBundle.getBundle("PageGenerator");
  131.         print(rb.getString("usage"));
  132.         System.exit(-1);
  133.     }
  134.  
  135.     /**
  136.      * @param    s Sring to display
  137.      * @return    void
  138.      */
  139.     static void print(String s) {
  140.         System.out.println(s);
  141.     }
  142. }
  143.  
  144.